﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;

public partial class zxgztj : System.Web.UI.Page
{
    protected string html_title;
    protected string html_title_fy_ts;
    protected string html_table_thead;
    protected string html_table_tBody;
    protected string get_str;
    protected ZXTJLX_Obj obj;
    protected void Page_Load(object sender, EventArgs e)
    {
        //默认值
        this.EnableViewState = false;
        ffydm.Text = "2760";
        fydm.Text = "0";
        tsdm.Text = "0";
        fymc.Text = "";
        tsmc.Text = "";
        rymc.Text = "";
        tjlx.Text = "";
        ksrq.Text = (int.Parse(DateTime.Now.Year.ToString("0000")) - 1).ToString() + "-" + "12-21";
        jsrq.Text = DateTime.Now.ToString("yyyy-MM-dd");
        //获取QueryString的值
        setValueByQueryString(ffydm, "ffydm");
        setValueByQueryString(fydm, "fydm");
        setValueByQueryString(tsdm, "tsdm");
        setValueByQueryString(fymc, "fymc");
        setValueByQueryString(tsmc, "tsmc");
        setValueByQueryString(rymc, "rymc");
        setValueByQueryString(ksrq, "ksrq");
        setValueByQueryString(jsrq, "jsrq");
        setValueByQueryString(tjlx, "tjlx");
        //格式校验更正
        ksrq.Text = ksrq.Text.Replace('/', '-');
        jsrq.Text = jsrq.Text.Replace('/', '-');
        //保存部分数据
        get_str = "&ksrq=" + ksrq.Text + "&jsrq=" + jsrq.Text + "&tjlx=" + tjlx.Text;
        
        //获取数据
        DataTable dt=null;
        if (fydm.Text.Trim() != "0")
        {
            string tt = "";
            ffydm.Text = "0";
            fymc.Text = ApplicationClass.MyCourt.GetFYMC(fydm.Text);
            if (tsdm.Text.Trim() != "0")
            {
                tsmc.Text = ApplicationClass.MyCourt.GetTSMC(fydm.Text, tsdm.Text);
                tt = "-" + tsmc.Text;
            }
            else
            {
                tsmc.Text = "";
            }
            this.html_title_fy_ts = string.Format("[{0}{1}]", fymc.Text,tt);
            
        
        }
        else
        {
            this.html_title_fy_ts = "[全区]";
        }
        
        obj = ApplicationClass.ZXTJLX_Manager.getZXTJLX_Obj(tjlx.Text);
        dt = BLL.ZXTJ_Service.GetZXGZTJ_Pro(ffydm.Text, fydm.Text, tsdm.Text, ksrq.Text, jsrq.Text, obj.ProcedureName);

       
       
        this.html_title = obj.Html_Title;
        this.html_table_thead = obj.Html_Table_Thead;
        if (dt != null && dt.Rows.Count > 0)
        {
            this.html_table_tBody = createTbody(dt);
        }
        
       
       
    }
    private void setValueByQueryString(TextBox box, string name)
    {
        string a = Request.QueryString[name];
        if (!string.IsNullOrEmpty(a))
        {
            box.Text = a.Trim();
        }
    }
    protected string createTitleTd(string content,string fydm,string tsdm)
    {
        return string.Format("<td><a href=\"zxgztj.aspx?fydm={1}&tsdm={2}{3}\" target=\"_self\">{0}</a></td>", content,fydm,tsdm, get_str);
    }
    protected string createFCTd(string content, string fydm,string fymc,string tsmc,string rymc,string hxh,string lxh)
    {
        fymc = HttpUtility.UrlEncode(fymc);
        tsmc = HttpUtility.UrlEncode(tsmc);
        rymc = HttpUtility.UrlEncode(rymc);
        
        return string.Format("<td><a href=\"caselist.aspx?webpagename=zxgztj_{8}&fydm={1}&fymc={2}&tsmc={3}&rymc={4}&hxh={5}&lxh={6}{7}\" target=\"_blank\">{0}</td>", content, fydm, fymc, tsmc, rymc, hxh, lxh, get_str, tjlx.Text);
    }
    protected string createUnLinkTd(string content)
    {
     
        return string.Format("<td>{0}</td>", content);
    }
  
    protected string createTr(DataRow dataRow, string rowNum)
    {
        StringBuilder  builder=new StringBuilder();
        string content = "";
        builder.AppendLine("<tr>");
        int columnsCount = dataRow.Table.Columns.Count;
        int dataRowStartIndex=7;
        builder.AppendLine(createTitleTd(dataRow["SHOWMC"].ToString(),dataRow["SHOWFYDM"].ToString(),dataRow["SHOWTSDM"].ToString()));
        int showColumnNum = 1;
        for (int i = dataRowStartIndex; i < columnsCount; i++)
        {
            content = contentFormat(dataRow[i].ToString(), showColumnNum);

            builder.AppendLine(createFCTd(content, dataRow["SHOWFYDM"].ToString(), dataRow["SHOWFYMC"].ToString(), dataRow["SHOWTSMC"].ToString(), dataRow["SHOWRYMC"].ToString(), rowNum, (i - dataRowStartIndex + 1).ToString()));
            showColumnNum++;
        }
       builder.AppendLine("</tr>");
       return builder.ToString();
    }
    private string contentFormat(string content, int lxh)
    {
        
        if (ExSystem.ExString.Contains(obj.money_columns, lxh.ToString())) content = "￥" + content;
        if (ExSystem.ExString.Contains(obj.people_columns, lxh.ToString())) content = content + "人";
        return content;
    }
    protected string createUnLinkTr(DataRow dataRow)
    {
        StringBuilder builder = new StringBuilder();
        builder.AppendLine("<tr>");
        int columnsCount = dataRow.Table.Columns.Count;
        int dataRowStartIndex = 7;
        string content;
        int lxh = 0;
        for (int i = dataRowStartIndex-1; i < columnsCount; i++)
        {
            content = contentFormat(dataRow[i].ToString(), lxh);
            builder.AppendLine(createUnLinkTd(content));
            lxh++;
        }
        builder.AppendLine("</tr>");
        return builder.ToString();
    }
    protected string createTbody(DataTable  dt)
    {
        StringBuilder builder = new StringBuilder();
        int i= dt.Rows.Count;
        for(int j=0;j<i;j++)
        {
            if (dt.Rows[j]["SHOWMC"].ToString().Trim() == "合计")
            {
                builder.AppendLine(createUnLinkTr(dt.Rows[j]));
                continue;
            }
            builder.AppendLine(createTr(dt.Rows[j], (j + 1).ToString()));
        }
        return builder.ToString();
    }


   
}

